//
//  QLPublishLifeInvitatCell.m
//  神约
//
//  Created by qlwl on 17/2/8.
//  Copyright © 2017年 qlwl. All rights reserved.
//

#import "QLPublishLifeInvitatCell.h"
#import "UIView+Frame.h"

#define InteritemSpacing (8)
#define InterNum (4)
#define CellWidth (iphoneWidth-(InterNum - 1)*InteritemSpacing - 20)/InterNum
#define CellHeight (CellWidth)

@implementation QLPublishAddImaSkillCollCell
- (IBAction)deleteBtnClick:(id)sender {
    if (self.deleteBtnClick) {
        self.deleteBtnClick();
    }
}

@end

@implementation QLPublishLifeInvitatCell5
- (void)setImaArray:(NSMutableArray *)imaArray
{
    _imaArray = imaArray;
    ((UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout).minimumLineSpacing = InteritemSpacing;
    [self.collectionView reloadData];
    
    self.b_h = 28 + CellHeight + 7;
}
#pragma mark CollectionViewDelegate
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (self.imaArray.count < 8) {
        return self.imaArray.count + 1;
    }else{
        return self.imaArray.count;
    }
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    QLPublishAddImaSkillCollCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QLPublishAddImaSkillCollCell" forIndexPath:indexPath];
    cell.imaView.clipsToBounds = YES;
    if (indexPath.row == self.imaArray.count) {
        cell.imaView.image = [UIImage imageNamed:@"publishAddIma"];
        cell.deleateBtn.hidden = YES;
    }else{
        cell.imaView.image = self.imaArray[indexPath.row];
        cell.deleateBtn.hidden = NO;
    }
    cell.deleteBtnClick = ^{
        if (self.deleteBtnClick) {
            self.deleteBtnClick(indexPath.row);
        }
    };
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(CellWidth, CellHeight);
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0,0,0,0);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.imaArray.count == indexPath.row) {
        if (self.addImaClick) {
            self.addImaClick();
        }
    }else{
        if (self.imaClick) {
            self.imaClick(indexPath.row);
        }
    }
}
@end

@implementation QLPublishLifeInvitatCell4
- (void)textViewDidChange:(UITextView *)textView
{
    if (self.contentChanged) {
        self.contentChanged(textView.text);
    }
}

@end

@implementation QLPublishLifeInvitatCell3
- (IBAction)selectBtnClick:(id)sender {
    UIButton * btn = sender;
    btn.selected = !btn.selected;
    if (self.selectBtnClick) {
        self.selectBtnClick(btn.selected);
    }
}

@end

@implementation QLPublishLifeInvitatCell2


@end

@implementation QLPublishLifeInvitatCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (IBAction)contentChanged:(id)sender {
    UITextField * field = sender;
    if (self.contentEditChanged) {
        self.contentEditChanged(field.text);
    }
}

@end
